package dviz.tools;

import java.util.HashMap;

import sun.security.action.GetLongAction;

import com.jme.light.DirectionalLight;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;

import dviz.visualSystem.impl.AnimationObject;

/**
 * @author zxq071000
 */
public class BaseAniObject extends AnimationObject {
	protected float colorRed;
	protected float colorBlue;
	protected float colorGreen;
	protected float colorAlpha;
	protected LightState lightState;
	protected float alpha;
	protected float beta;

	/**
	 * @param alpha
	 * @uml.property name="alpha"
	 */
	public void setAlpha(float alpha) {
		this.alpha = alpha;
		updateMatrix();
	}

	/**
	 * @param beta
	 * @uml.property name="beta"
	 */
	public void setBeta(float beta) {
		this.beta = beta;
		updateMatrix();
	}

	void updateMatrix() {
		// getRenderNode().getLocalRotation().set
		Quaternion quaternion = new Quaternion();
		quaternion.fromAngles(alpha, beta, 0);
		getRenderNode().setLocalRotation(quaternion);
	}

	/**
	 * @param colorAlpha
	 * @uml.property name="colorAlpha"
	 */
	public void setColorAlpha(float colorAlpha) {
		this.colorAlpha = colorAlpha;
	}

	/**
	 * @param colorRed
	 * @uml.property name="colorRed"
	 */
	public void setColorRed(float colorRed) {
		this.colorRed = colorRed;
	}

	/**
	 * @param colorBlue
	 * @uml.property name="colorBlue"
	 */
	public void setColorBlue(float colorBlue) {
		this.colorBlue = colorBlue;

	}

	/**
	 * @param colorGreen
	 * @uml.property name="colorGreen"
	 */
	public void setColorGreen(float colorGreen) {
		this.colorGreen = colorGreen;
	}

	public void setScale(float scale) {
		getRenderNode().setLocalScale(scale);
	}

	public void setScaleX(float sx) {
		getRenderNode().getLocalScale().setX(sx);
	}

	public void setScaleY(float sy) {
		getRenderNode().getLocalScale().setY(sy);
	}

	public void setScaleZ(float sz) {
		getRenderNode().getLocalScale().setZ(sz);
	}

	public void setX(float x) {
		getRenderNode().getLocalTranslation().setX(x);
	}

	public void setY(float y) {
		getRenderNode().getLocalTranslation().setY(y);
	}

	public void setZ(float z) {
		getRenderNode().getLocalTranslation().setZ(z);
	}

	public void setRotateW(float w) {
		getRenderNode().getLocalRotation().w = w;
	}

	public void setRotateX(float x) {
		getRenderNode().getLocalRotation().x = x;
	}

	public void setRotateY(float x) {
		getRenderNode().getLocalRotation().y = x;
	}

	public void setRotateZ(float x) {
		getRenderNode().getLocalRotation().z = x;
	}

	DirectionalLight dl;

	public BaseAniObject(HashMap<String, Object> initVector) {
		super(initVector);
		// if (initVector.get("colorRed") != null)
		// colorRed = new Float(initVector.get("colorRed").toString());
		// if (initVector.get("colorGreen") != null)
		// colorGreen = new Float(initVector.get("colorGreen").toString());
		// if (initVector.get("colorBlue") != null)
		// colorBlue = new Float(initVector.get("colorBlue").toString());
		// if (initVector.get("colorBlue") != null)
		// colorBlue = new Float(initVector.get("colorBlue").toString());
		lightState = DisplaySystem.getDisplaySystem().getRenderer()
				.createLightState();
		lightState.setEnabled(true);
		{
			dl = new DirectionalLight();
			dl.setDirection(new Vector3f(1, -1, 1));
			dl.setDiffuse(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setAmbient(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setEnabled(true);
			lightState.attach(dl);
		}
		{
			dl = new DirectionalLight();
			dl.setDirection(new Vector3f(-1, -1, 1));
			dl.setDiffuse(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setAmbient(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setEnabled(true);
			lightState.attach(dl);
		}
		{
			dl = new DirectionalLight();
			dl.setDirection(new Vector3f(1, -1, -1));
			dl.setDiffuse(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setAmbient(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setEnabled(true);
			lightState.attach(dl);
		}
		{
			dl = new DirectionalLight();
			dl.setDirection(new Vector3f(-1, -1, -1));
			dl.setDiffuse(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setAmbient(new ColorRGBA(colorRed, colorGreen, colorBlue, 1));
			dl.setEnabled(true);
			lightState.attach(dl);
		}
		getRenderNode().setRenderState(lightState);
	}

	@Override
	public void renderUpdate(float fpt) {
		super.renderUpdate(fpt);
		dl
				.setAmbient(new ColorRGBA(colorRed, colorGreen, colorBlue,
						colorAlpha));
		dl
				.setDiffuse(new ColorRGBA(colorRed, colorGreen, colorBlue,
						colorAlpha));
		// getRenderNode().updateRenderState();
	}

}
